/**
 * Copyright(C) 2012 Luvina
 * MstGroupLogicImpl.java, 27-05-2012 NguyenVietDung
 */
package net.luvina.manageuser.logic.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.faces.model.SelectItem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sun.org.apache.bcel.internal.generic.LSTORE;

import net.luvina.manageuser.dao.MstGroupDao;
import net.luvina.manageuser.hibernate.MstGroup;
import net.luvina.manageuser.logic.MstGroupLogic;

/**
 * MstGroupLogicImpl: Implement MstGroupLogic để xử lý logic cho các chức năng
 * liên quan đến mst_group
 *
 * @author NguyenVietDung
 */
@Service("mstGroupLogic")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false, rollbackFor = { Throwable.class })
public class MstGroupLogicImpl implements MstGroupLogic {
	@Autowired
	private MstGroupDao mstGroupDao;

	/*
	 * (non-Javadoc)
	 *
	 * @see net.luvina.manageuser.logic.MstGroupLogic#getListItemGroup()
	 */
	@Override
	public List<SelectItem> getListItemGroup(String title) {
		// TODO Auto-generated method stub
		List<MstGroup> lsMstGroups = this.mstGroupDao.getListGroup();
		List<SelectItem> lsMstGroupSelectItem = new ArrayList<SelectItem>();
		lsMstGroupSelectItem.add(new SelectItem("", title));
		SelectItem tmpSelectItem;
		for (MstGroup item : lsMstGroups) {
			tmpSelectItem = new SelectItem(item.getGroupId(), item.getGroupName());
			lsMstGroupSelectItem.add(tmpSelectItem);
		}

		return lsMstGroupSelectItem;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see net.luvina.manageuser.logic.MstGroupLogic#existMstGroup(int)
	 */
	@Override
	public boolean existMstGroup(int groupId) {
		boolean isExist = this.mstGroupDao.existMstGroup(groupId);
		if (!isExist) {
			return false;
		}
		return true;
	}
}
